package 常用api;

import java.util.Arrays;
import java.util.Comparator;
import java.util.function.IntToLongFunction;

public class arrays {

    public static void main(String[] args) {
        long[] a = {1, 2, 3, 4, 5, 6, 7, 8};
        System.out.println(Arrays.toString(a));
        System.out.println(Arrays.toString(Arrays.copyOfRange(a, 2, 5)));
        long[] b = Arrays.copyOf(a, 99);
        System.out.println(Arrays.toString(b));
        Arrays.setAll(b, new IntToLongFunction() {
            @Override
            public long applyAsLong(int value) {
                return b[value] * 2;
            }
        });
        System.out.println(Arrays.toString(b));
        Arrays.sort(b);
        System.out.println(Arrays.toString(b));
        Student[] students = new Student[10];
        int i = 999;
        for (int j = 0; j < 10; j++) {
            students[j] = new Student();
            students[j].age = i;
            i--;
        }
        Arrays.sort(students);
        for (Student student : students) {
            System.out.println(student.age);
        }
        Student2[] students2 = new Student2[10];
         i = 999;
        for (int j = 0; j < 10; j++) {
            students2[j] = new Student2();
            students2[j].age = i;
            i--;
        }
        Arrays.sort(students2, new Comparator<Student2>() {
            @Override
            public int compare(Student2 o1, Student2 o2) {
                return o1.age - o2.age;
            }
        });
        for (Student2 student : students2) {
            System.out.println(student.age);
        }
    }
}
